function[distancia]=distancia_letras(xbin)
[topline,upperbaseline,downbaseline,downline,ancho_cuerpo]=lineas_palabra(xbin);
[m,n]=size(xbin);
x2=ones(m,n);
for j=1:n
    con=1;
    cont=0;
    for i=1:m
        if xbin(i,j)==0
            cont=cont+con;
            con=con+1;
        end        
    end
    f=m-cont;
    if f<1
        f=1;
    end
    x2([f:m],j)=0;
end
%figure;
%imshow(x2);
cont=[];
j=1;
%umbral=round((downline-topline)/2);

negros=[];
for i=1:m
    con=length(find(x2(i,:)==0));
    if con ~= 0
        negros=[negros con];
    end
end
f1=find(negros==max(negros(find(negros<(min(negros)+20)))));
umbral=m - (length(negros)-max(f1));

while j<=n
    if x2(umbral,j)==0
        cont=[cont j];
        while (j<=n)&&(x2(umbral,j)==0)
            j=j+1;
        end
    else
        j=j+1;
    end
end
contar=[];
for r=1:length(cont)-1
    contar=[contar (cont(r+1)-cont(r))];
end

if isempty(contar)
    distancia=0;
else
    distancia=mean(contar);
end

